import numpy as np
# index
a=np.array([1,2,3,4,5])
print(a[4],a[-1])
b=np.array([[1,3,5,7],
            [2,4,6,8],
            [7,8,9,10]])
print(b[1,2],b[2][3],b[-1,-2])
# slice
a=np.array([1,3,5,7,9])
print(a[1:3],a[:3],a[1:],a[1:-1])
print(a[1:-1:2])
# 2d array
b=np.array([[1,2,3],
            [4,5,6],
            [7,8,9]])
slice=b[1:2,1:2]
print(slice,slice.shape)
print(b[:2,1:])
print(b[1:,1])
# bool index
a1=np.array([1,2,3,4])
b1=np.array([True,False,True,False])
print(a1[b1])
# 2d array bool index
a2=np.array([[1,2,3],
             [4,5,6],
             [7,8,9]])
b2=np.array([[True,False,True],
             [True,False,True],
             [True,False,True]])
print(a2[b2])
# deep copy
a3=np.array([1,2,3])
b3=np.array([False,True,True])
c=a3[b3]
print(c)
c[1]=100
print(c)
print(a3)
# shallow copy
a4=np.array([7,8,9])
b4=np.array([False,True,True])
c4=a4[1:]
print(c4)
c4[1]=100
print(c4)
print(a4)
# fancy index
a1=np.array([1,2,3,4,5,6])
b=[1,2,3,4]
print(a1[b])
c=np.array([1,2,3,4])
print(a1[c])
d=np.array([[1,2],
           [3,4]])
print(a[d])
# 2d array fancy index
a2=np.array([[1,2,3],
             [4,5,6],
             [7,8,9]])
m=[1,2]
n=[0,1]
print(a2[m,n])
print(a2[m][n])
m=np.array([1,2])
n=np.array([0,1])
print(a2[m,n])
m=np.array([[1,1],
            [2,0]])
n=np.array([[1,0],
            [2,2]])
print(a2[m,n])
m=[1,2]
print(a2[m,2])
m=np.array([1,2])
print(a2[m,2])
m=np.array([[1,1],
           [2,0]])
print(a2[m,2])
